import request from '@/utils/request/request';
import type { MusicItem } from '@/types/music';
import type { CommonResponse } from '@/types/response';

interface MusicListResponse{
  list: MusicItem[];
}

// 获取音乐列表（支持分页、标签搜索和状态过滤）
export const getMusicList = (tags?: string): Promise<CommonResponse<MusicListResponse>> => 
  request.get('/music/list', { tags });

// 获取音乐详情
export const getMusic = (musicId: number): Promise<CommonResponse<MusicItem>> => 
  request.get(`/music/${musicId}`);

// 新增音乐
export const addMusic = (music: Omit<MusicItem, 'id'>): Promise<CommonResponse<MusicItem>> => 
  request.post('/music', music);

// 更新音乐信息
export const updateMusic = (music: MusicItem): Promise<CommonResponse<MusicItem>> => 
  request.put('/music', music);

// 删除音乐
export const deleteMusic = (musicId: number): Promise<CommonResponse<void>> => 
  request.delete(`/music/${musicId}`);

// 收藏/取消收藏音乐
export const toggleCollect = (musicId: number): Promise<CommonResponse<void>> => 
  request.put(`/music/collect/${musicId}`);

// 获取推荐音乐列表
export const getRecommendations = (): Promise<CommonResponse<MusicItem[]>> => 
  request.get('/music/recommend');